package com.example.myapplication2

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import com.example.myapplication2.MainActivity

class MainActivity : ComponentActivity() {


    val expert= ProgramAdviserModel()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.layout)
        val spinner = findViewById<Spinner>(R.id.spinner)
        val button = findViewById<Button>(R.id.button)
        val textView = findViewById<TextView>(R.id.textView)

        button.setOnClickListener {
            val selectedFeature = spinner.selectedItem?.toString() ?: "未选择"
            textView.text = expert.getLanguage(selectedFeature)
        }
        val dynamicText: LinearLayout=findViewById(R.id.dynamic_texts)
        val buttonAddText: Button=findViewById(R.id.button2)
        buttonAddText.setOnClickListener {
            val count=dynamicText.childCount+1
            val newtextView = TextView(this).apply{
                text="This is a new TextView: $count\n"
                textSize=16f
                setTextColor(android.graphics.Color.RED)
                setBackgroundColor(android.graphics.Color.YELLOW)
                setPadding(16,12,16,12)
            }
            dynamicText.addView(newtextView)  // 正确：添加刚创建的文本视图
        }
    }}